<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String baseBath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <base href=<%=baseBath%>
    <%@include file="../common_css.jsp"%>
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
    <input type="hidden" name="id" value="${cusIntention.id}">
    <input type="hidden" name="InputIntentionState" value="${cusIntention.intentionState}">
    <input type="hidden" name="InputSource" value="${cusIntention.customer.source}">
    <input type="hidden" name="InputUserId" value="${cusIntention.customer.userId}">
    <input type="hidden" name="InputDriveInterest" value="${cusIntention.driveInterest}">
    <input type="hidden" name="InputIntentionLevel" value="${cusIntention.intentionLevel}">
    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">客户名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       name="name" id="name"  lay-verify="required" value="${cusIntention.customer.name}" placeholder="请输入客户名"
                <c:if test="${cusIntention.customer.name != null}">disabled</c:if>
                >
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       name="phone" id="phone" lay-verify="phone" value="${cusIntention.customer.phone}" placeholder="请输入手机号"
                       <c:if test="${cusIntention.customer.name != null}">disabled</c:if>
                >
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">微信</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       name="weixin"  id="weixin"  value="${cusIntention.customer.weixin}" placeholder="请输入微信号"
                       <c:if test="${cusIntention.customer.name != null}">disabled</c:if>
                >
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label">客户来源</label>
            <div class="layui-input-block">
                <select name="source"  id="source">
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">客户等级</label>
            <div class="layui-input-block">
                <select name="intentionLevel"  id="intentionLevel">
                </select>
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label">试驾兴趣</label>
            <div class="layui-input-block">
                <select name="driveInterest"  id="driveInterest">
                </select>
            </div>
        </div>
    </div>

<div class="layui-form-item layui-row">
    <div class="layui-col-xs6">
        <label class="layui-form-label">线索状态</label>
        <div class="layui-input-block">
            <select name="intentionState" id="intentionState"
                    <c:if test="${cusIntention.customer.name != null}">disabled</c:if>
            >
            </select>
        </div>
    </div>
    <div class="layui-col-xs6">
        <label class="layui-form-label">销售人员</label>
        <div class="layui-input-block">
            <select name="userId"  id="userId">

            </select>
        </div>
    </div>
</div>

<div class="layui-form-item layui-row">
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">客户描述</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入对客户的描述" name="describe" class="layui-textarea">${cusIntention.describe}</textarea>
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">客户关注点</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入客户关注点" name="focus" class="layui-textarea">${cusIntention.focus}</textarea>
        </div>
    </div>
</div>

<br/>
<div class="layui-form-item layui-row layui-col-xs12">
    <div class="layui-input-block">
        <button class="layui-btn layui-btn-lg" lay-submit=""
                lay-filter="addOrUpdateCustomer">确认
        </button>
        <button class="layui-btn layui-btn-lg layui-btn-normal">取消</button>
    </div>
</div>
</form>
<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;
        $.post("/dictionaries/findIntentionState",function (res) {
            //console.log(res)
            for(var i=0;i<res.length;i++){
                //绑定下拉框显示
                if($("input[name='InputIntentionState']").val() == res[i].valueId){
                    $("#intentionState").append("<option value=\""+res[i].valueId+"\"  selected='selected' >"+res[i].valueName+"</option>");
                }else{
                    $("#intentionState").append("<option value=\""+res[i].valueId+"\"   >"+res[i].valueName+"</option>");
                }

            }
            // 重新渲染下拉框内容
            layui.form.render("select");
        });
        $.post("/dictionaries/findDriveInterest",function (res) {
            //console.log(res)
            for(var i=0;i<res.length;i++){
                //绑定下拉框显示
                if($("input[name='InputDriveInterest']").val() == res[i].valueId){
                    $("#driveInterest").append("<option value=\""+res[i].valueId+"\"  selected='selected' >"+res[i].valueName+"</option>");
                }else{
                    $("#driveInterest").append("<option value=\""+res[i].valueId+"\"   >"+res[i].valueName+"</option>");
                }

            }
            // 重新渲染下拉框内容
            layui.form.render("select");
        });
        $.post("/user/findUser",function (res) {
            //console.log(res)
            for(var i=0;i<res.length;i++){
                //绑定下拉框显示
                if($("input[name='InputUserId']").val() == res[i].id){
                    $("#userId").append("<option value=\""+res[i].id+"\"  selected='selected' >"+res[i].name+"</option>");
                }else{
                    $("#userId").append("<option value=\""+res[i].id+"\"   >"+res[i].name+"</option>");
                }
            }
            // 重新渲染下拉框内容
            layui.form.render("select");
        });
        $.post("/activity/findActivity",function (res) {
            //console.log(res)
            for(var i=0;i<res.length;i++){
                //绑定下拉框显示
                if($("input[name='InputSource']").val() == res[i].id){
                    $("#source").append("<option value=\""+res[i].id+"\"  selected='selected' >"+res[i].name+"</option>");
                }else{
                    $("#source").append("<option value=\""+res[i].id+"\"   >"+res[i].name+"</option>");
                }
            }
            // 重新渲染下拉框内容
            layui.form.render("select");
        });
        $.post("/dictionaries/findIntentionLevel",function (res) {
            //console.log(res)
            for(var i=0;i<res.length;i++){
                //绑定下拉框显示
                if($("input[name='InputIntentionLevel']").val() == res[i].valueId){
                    $("#intentionLevel").append("<option value=\""+res[i].valueId+"\"  selected='selected' >"+res[i].valueName+"</option>");
                }else{
                    $("#intentionLevel").append("<option value=\""+res[i].valueId+"\"   >"+res[i].valueName+"</option>");
                }
            }
            // 重新渲染下拉框内容
            layui.form.render("select");
        });



        form.on('submit(addOrUpdateCustomer)',function (data) {
            var index= top.layer.msg("数据提交中,请稍后...",{icon:16,time:false,shade:0.8});

            var url = "/cusIntention/insert";
            if($("input[name='id']").val()){
                url="/cusIntention/update";
            }
            $.post(url,data.field,function (res) {
                if(res=='success'){
                    top.layer.msg("操作成功");
                    top.layer.close(index);
                    layer.closeAll("iframe");
                    // 刷新父页面
                    parent.location.reload();
                }
            });
            return false;
        });
    });
</script>
</body>
</html>